/**
 * 股票交易的命令模式
 */

class Stock{
     constructor(){}
     static buy(id,money){
        console.log(`buy ${id} stock ,money is ${money}`)
     }
     static sell(id,money){
        console.log(`sell ${id} stock ,money is ${money}`)
     }
}

class StockExec{
    constructor(type,id,money){
        this.type = type
        this.id = id
        this.money = money
    }
    exec(){
        if(this.type==='buy') Stock.buy(this.id,this.money)
        else Stock.sell(this.id,this.money)
    }
}

class Commond {
    constructor(){
        this.commond = []
    }
    add(c){
        this.commond.push(c)
    }
    execAll(){
        for(let c of this.commond){
            c.exec()
        }
    }
}

const commonds = new Commond()
commonds.add(new StockExec('buy',1,2222))
commonds.add(new StockExec('buy',4,252))
commonds.add(new StockExec('sell',5,12))
commonds.add(new StockExec('sell',5,2))
commonds.add(new StockExec('buy',1,2222))
commonds.add(new StockExec('buy',1,2222))

console.log('开始执行')
//命令模式，前面全部存着，最后一起执行
commonds.execAll()